package org.sample.springbootactivemq.config;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;

@Configuration
public class MessageSenderConfig {

	@Value("${activemq.broker-url}")
	private String brokerUrl;

	@Bean
	public ActiveMQConnectionFactory activeMQConnectionFactory() {

		ActiveMQConnectionFactory activeMQConnectionFactory =
				new ActiveMQConnectionFactory();

		activeMQConnectionFactory.setBrokerURL(brokerUrl);

		return activeMQConnectionFactory;
	}

	@Bean
	public CachingConnectionFactory cachingConnectionFactory(
			@Autowired ActiveMQConnectionFactory activeMQConnectionFactory) {

		return new CachingConnectionFactory(activeMQConnectionFactory);
	}

	@Bean
	public JmsTemplate jmsTemplate(@Autowired CachingConnectionFactory cachingConnectionFactory) {

		return new JmsTemplate(cachingConnectionFactory);
	}


}
